var _timer = 30000;
var _split = 1;
var _id = 0;
var _top10 = new Array(10); // e 10 W

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=snow3&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate21(a[0]);
	show_rate22(a[1]);
	show_titleAmu(a[2]);
	window.status = "";
	
	timer_id = setTimeout("timer()", _timer);
}

function show_rate21(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num21_"+i].innerHTML = _name21[i];
		document.all["rate21_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount21_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1006&numbers="+i+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount21_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg21_"+i].innerHTML = "<input type=button onclick=\"ratediff(21,'"+i+"',1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(21,'"+i+"',-1)\" value=\"&Phi;\" class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win21_"+i].innerHTML = win1;
		document.all["win21_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.amount21.innerHTML=Math.floor(amount0);
}


function gen_rate21()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb21head;
	ret += "</tr>";
	
	for (j=0; j<6; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num21_"+k+" class=td6 align=center></td><td id=amount21_"+k+"></td><td nowrap id=win21_"+k+"></td><td id=rate21_"+k+" class=rate></td><td align=center id=chg21_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div21.innerHTML = ret;
}

function show_rate22(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<11; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num22_"+i].innerHTML = _name22[i];
		document.all["rate22_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount22_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1007&numbers="+i+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount22_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg22_"+i].innerHTML = "<input type=button onclick=\"ratediff(22,'"+i+"',1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(22,'"+i+"',-1)\" value=\"&Phi;\" class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win22_"+i].innerHTML = win1;
		document.all["win22_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.amount22.innerHTML=Math.floor(amount0);
}

function gen_rate22()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb22head;
	ret += "</tr>";
	
	for (j=0; j<5; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num22_"+k+" class=td6 align=center></td><td nowrap id=amount22_"+k+"></td><td nowrap id=win22_"+k+"></td><td id=rate22_"+k+" class=rate></td><td align=center id=chg22_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div22.innerHTML = ret;
}

function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}

function ratediff(btype, num, rate)
{
	//window.status = "Cange Rate....";
	if (timer_id) clearTimeout(timer_id);
    XH1.open("POST", "op.php?op=subsidary&fp=ratediff&id="+_id+"&bettype="+btype+"&number="+num+"&rate="+rate,false); 
    try{XH1.send("");}catch(E){}
    window.status = "";
    timer();
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate21();
	gen_rate22();
	timer();
}

window.onload = winonload;